/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.core.entity.boardgame;

import com.playground.core.entity.Player;

/**
 * Represents a piece in a board game. A piece aways occupie a square and there's
 * aways a player who owns it.
 * 
 * In a checkers game, for example, there are (initially) 12 pieces for each player,
 * each occupying one of the 64 avaiable squares.
 * 
 * @author Tiago Peres
 */
public class Piece {
    private final long id;
    // the owner of this piece
    private Player owner;
    // the square being occupied by this piece
    private Square square;
    
    public Piece(long id){
        this.id = id;
    }

    public Player getOwner() {
        return owner;
    }

    public void setOwner(Player owner) {
        this.owner = owner;
    }

    public Square getSquare() {
        return square;
    }

    public void setSquare(Square square) {
        this.square = square;
    }

    public long getId() {
        return id;
    }
    
    @Override
    public boolean equals(Object o){
        if (null != o && Piece.class.isAssignableFrom(o.getClass())){
            if (((Piece) o).getId() == this.getId()){
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
}
